﻿
Imports bithelper

Public Class bitarray
    Private bits() As Byte = Nothing

    Public Sub New(ByVal size As Int64)
        ReDim bits(ifoper((size Mod bitcountInByte) = 0, (size >> bitshiftInByte) - 1, size >> bitshiftInByte))
    End Sub

    Private Shared Function arrayIndex(ByVal i As Int64) As Int64
        Return i >> bitshiftInByte
    End Function

    Private Shared Function indexInArray(ByVal i As Int64) As Int64
        Return (i And (bitcountInByte - 1))
    End Function

    Default Public Property at(ByVal i As Int64) As Boolean
        Get
            Return getbit(bits(arrayIndex(i)), indexInArray(i))
        End Get
        Set(ByVal value As Boolean)
            setbit(bits(arrayIndex(i)), indexInArray(i), value)
        End Set
    End Property
End Class
